"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const maishu_chitu_admin_1 = require("maishu-chitu-admin");
const gateway_1 = require("maishu-node-auth/gateway");
const path = require("path");
const global_1 = require("./global");
var global_2 = require("./global");
exports.merchantRoleId = global_2.merchantRoleId;
var global_3 = require("./global");
exports.stationPath = global_3.stationPath;
async function start(settings) {
    let permissions = {};
    permissions[`${global_1.stationPath}*`] = { roleIds: [global_1.merchantRoleId] };
    maishu_chitu_admin_1.start({
        port: settings.port,
        rootDirectory: __dirname,
        station: {
            gateway: settings.gateway,
            path: global_1.stationPath,
            permissions: permissions
        },
        virtualPaths: {
            "node_modules": path.join(__dirname, "../node_modules")
        }
    });
    let dc = await gateway_1.createDataContext({ db: settings.gatewayDB, logLevel: settings.logLevel });
    let merchantRole = await dc.roles.findOne(global_1.merchantRoleId);
    if (merchantRole == null) {
        merchantRole = { id: global_1.merchantRoleId, name: "商户", create_date_time: new Date(Date.now()) };
        await dc.roles.insert(merchantRole);
    }
}
exports.start = start;
